let app = getApp()
Component({ 
    properties: {
         pagetitle:String,
         parent:String,
         sourceList:Array 
      },
      data:{
        list: [],
        editStatus:0,
        editindex:0,
        checkedId: 1,
        validate: {
            consigner: [ {
                rule:'\S+',
                message: "收件人名称不能为空"
            } ],
            phone: [{
                rule:'^1\d{10}$',
                message: "手机号格式不正确"
            } ],
            areaCode: [ {
              rule:'\S+',
              message: "请选择收货区域"
            } ],
            address: [ {
                rule:'\S+',
                message: "请填写收货详细地址"
            } ]
        },
        errorMsg: {
            message: "",
            name: "",
            index: -1
        },
        page_path: "pages/address/address"
      },
    lifetimes: {
        attached: function () {
          this.setData({
            globalColor:app.globalData.globalColor,
          })
          var project_json =wx.getStorageSync('selfAddress');
          for (let i = 0; i < project_json.length; i++) {
            project_json[i]['new_addr']=JSON.parse(project_json[i].address)
          }
          this.setData({
            list:project_json
          })
       }
      },
    methods: {
      choose:function(e){
           var list=this.data.list
           var name=list[e.currentTarget.dataset.index].name
           wx.setStorageSync('selfAddr',name)
           wx.navigateBack({changed: true });
      },
      location:function(e){
           var list=this.data.list
           var lat=list[e.currentTarget.dataset.index].new_addr.postion_lat
           var long=list[e.currentTarget.dataset.index].new_addr.postion_lng
           var name=list[e.currentTarget.dataset.index].name
           wx.openLocation({
            type: 'gcj02',
            latitude:Number(lat),
            longitude:Number(long),
            name:name,
            scale:28
          }) 
      }
    }
});
